package com.xingkeduo.business.user.event;

import com.netflix.client.ClientException;
import com.xingkeduo.util.pojo.exception.CommunicationException;
import com.xingkeduo.util.pojo.exception.SystemException;
import feign.RetryableException;
import lombok.extern.slf4j.Slf4j;

/**
 * 远程事件异常情况
 *
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/7/18 21:49
 **/
@Slf4j
public class FeignException {

    /**
     * 远程服务异常情况处理
     *
     * @param t:
     * @return : void
     * @author : gaozifeng
     * @date : 2019/7/18 21:26
     */
    public static void feignExceptionHandle(Throwable t) {
        if (t instanceof ClientException) {
            throw new CommunicationException(CommunicationException.Type.DEFAULT, "链接失败");
        } else if (t instanceof RetryableException) {
            log.info("feign远程调用没有及时返回 read time out");
            throw new SystemException(SystemException.Type.DEFAULT, "人数太多,请稍后重试");
        } else if (t instanceof RuntimeException) {
            throw new SystemException(SystemException.Type.DEFAULT, "没有找到远程服务");
        }
    }
}
